// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import Shader from "../Shader";


const { ccclass, property } = cc._decorator;

@ccclass
export default class OutlineShader extends Shader {
    @property(cc.Color)
    private _outlineColor: cc.Color = cc.Color.WHITE;
    @property(cc.Color)
    public get outlineColor(): cc.Color {
        return this._outlineColor;
    }
    public set outlineColor(value: cc.Color) {
        this._outlineColor = value;
        this.setProperty("u_color", this._outlineColor);
    }

    @property
    private _outlineWith: number = 4;
    @property
    public get outlineWith(): number {
        return this._outlineWith;
    }
    public set outlineWith(value: number) {
        this._outlineWith = value;
        this.setProperty("u_size", this._outlineWith);
    }

    @property
    private _minAlpha: number = 0;
    @property
    public get minAlpha(): number {
        return this._minAlpha;
    }
    public set minAlpha(value: number) {
        this._minAlpha = value;
        this.setProperty("u_minAlpha", this._minAlpha);
    }

    @property
    private _maxAlpha: number = 1;
    @property
    public get maxAlpha(): number {
        return this._maxAlpha;
    }
    public set maxAlpha(value: number) {
        this._maxAlpha = value;
        this.setProperty("u_maxAlpha", this._maxAlpha);
    }

    protected start(): void {
        this.setProperty("u_color", this._outlineColor);
        this.setProperty("u_minAlpha", this._minAlpha);
        this.setProperty("u_maxAlpha", this._maxAlpha);
        this.setProperty("u_size", this._outlineWith);
        this.updateTexRatio();
    }

    private updateTexRatio() {
        // if (this.render) {
        //     let texture = (this.render as cc.Sprite).spriteFrame.getTexture();
        //     this.setProperty("u_texRatio", cc.v2(1 / texture.width, 1 / texture.height));
        // }
    }
}
